﻿using winS.UnityEditor.Undo;

namespace winS.UnityEditor.UIElement
{
    internal readonly struct ValueChangeCommand<T> : IUndoCommand
    {
        public readonly string info => "数据改变";

        private readonly T oldValue;
        private readonly T newValue;
        private readonly IUndoable<T> undoField;

        public ValueChangeCommand(IUndoable<T> undoField, T oldValue, T newValue)
        {
            this.undoField = undoField;
            this.oldValue = oldValue;
            this.newValue = newValue;
        }

        public void Redo()
        {
            undoField.Redo(newValue);
        }
        public void Undo()
        {
            undoField.Undo(oldValue);
        }
    }
}